﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using SLPropertyGrid;
using SLPropertyGrid.Converters;
using System.Reflection;
using System.Runtime.Serialization;

namespace FormDesigner
{
    [DataContract]
    public class HtmlTextBoxModel
    {
        private string textid;
        private TextBoxFormatType formattype;
        private int width = 90;
        private int height = 20;

        private int location_x;
        private int location_y;

        private DefaultEntryType defaultentry;

        public Label ctrl;

        public HtmlTextBoxModel(Label textbox)
        {
            this.ctrl = textbox;
        }

        [Editor(typeof(TextIdValueEditor))]
        [DataMember]
        [SLPropertyGrid.DisplayName("关联项")]
        [System.ComponentModel.Description("于该控件关联的文本")]
        public string TextId
        {
            get { return textid; }
            set
            {
                this.textid = value;
            }
        }

        [DataMember]
        [SLPropertyGrid.DisplayName("格式")]
        [System.ComponentModel.Description("是否加载时间选择控件")]
        public TextBoxFormatType FormatType
        {
            get { return formattype; }
            set { formattype = value; }
        }
        [DataMember]
        [SLPropertyGrid.DisplayName("宽度")]
        [System.ComponentModel.Description("用于修改该控件宽度")]
        public int Width
        {
            get { return width; }
            set
            {
                width = value;
                if (width <= 10)
                    width = 10;
                if (this.ctrl != null)
                    this.ctrl.Width = width;
            }
        }
        [DataMember]
        [SLPropertyGrid.DisplayName("高度")]
        [System.ComponentModel.Description("用于修改该控件高度")]
        public int Height
        {
            get { return height; }
            set
            {
                height = value;
                if (height <= 10)
                    height = 10;
                if (this.ctrl != null)
                    this.ctrl.Height = height;
            }
        }
        [DataMember]
        [Browsable(false)]
        public int LocationX
        {
            get
            {
                return ctrl != null ? location_x = (int)Canvas.GetLeft(ctrl) : location_x;
            }
            set
            {
                location_x = value;
                if (ctrl != null)
                    Canvas.SetLeft(ctrl, value);
            }
        }
        [DataMember]
        [Browsable(false)]
        public int LocationY
        {
            get
            {
                return ctrl != null ? location_y = (int)Canvas.GetTop(ctrl) : location_y;
            }
            set
            {
                location_y = value;
                if (ctrl != null)
                    Canvas.SetTop(ctrl, value);
            }
        }
        [DataMember]
        [SLPropertyGrid.DisplayName("默认项")]
        [System.ComponentModel.Description("用于加载文本默认值")]
        public DefaultEntryType DefaultEntry
        {
            get { return defaultentry; }
            set
            {
                this.defaultentry = value;
            }
        }
    }

    public enum TextBoxFormatType
    {
        文本 = 0,
        时间 = 1,
        时间时分 = 2,
        部门列表 = 3
    }

    public enum DefaultEntryType
    {
        请选择 = 0,
        填充时间 = 1,
        填充时间时分 = 2,
        填充员工姓名 = 3,
        填充员工部门 = 4
    }
}
